import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn,  } from "typeorm";
import { ManualTimestamp } from "../../../decorators/manual-timestamp.decorator";

export enum RPSStatus {
  PENDING = 0, // 等待应战
  IN_PROGRESS = 1, // 进行中
  COMPLETED = 2, // 已完成
  EXPIRED = 3, // 已过期
}

export enum RPSResult {
  CHALLENGER_WIN = 1, // 挑战者获胜
  RESPONDER_WIN = 2, // 应战者获胜
  DRAW = 3, // 平局
}

@Entity("casino_rock_paper_scissors")
@ManualTimestamp()
export class CasinoRockPaperScissors {
  @PrimaryGeneratedColumn()
  id!: number;

  // 移除 round_id 字段，因为数据库表中没有这个字段
  // @Column({ name: "round_id", type: "bigint", comment: "期数ID" })
  // // roundId!: number;

  @Column({ name: "challengerId", type: "int", comment: "发起者用户ID" })
  challengerId!: number;

  @Column({
    name: "challengerName",
    type: "varchar",
    length: 64,
    comment: "发起者名称",
  })
  challengerName!: string;

  @Column({
    name: "challengerValue",
    type: "tinyint",
    comment: "发起者出拳：1-石头，2-剪刀，3-布",
  })
  challengerValue!: number;

  @Column({ name: "betAmount", type: "bigint", comment: "下注金额" })
  betAmount!: number;

  @Column({ name: "currencyType", type: "tinyint", comment: "货币类型" })
  currencyType!: number;

  @Column({ name: "status", type: "tinyint", comment: "状态" })
  status!: number;

  @Column({
    name: "responderId",
    type: "int",
    nullable: true,
    comment: "应战者用户ID",
  })
  responderId!: number | null;

  @Column({
    name: "responderName",
    type: "varchar",
    length: 64,
    nullable: true,
    comment: "应战者名称",
  })
  responderName!: string | null;

  @Column({
    name: "responderValue",
    type: "tinyint",
    nullable: true,
    comment: "应战者出拳：1-石头，2-剪刀，3-布",
  })
  responderValue!: number | null;

  @Column({
    name: "winnerId",
    type: "int",
    nullable: true,
    comment: "获胜者用户ID",
  })
  winnerId!: number | null;

  @Column({ name: "winAmount", type: "bigint", comment: "获胜金额" })
  winAmount!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;
@Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;
// 计算属性
  get isWaiting(): boolean {
    return this.status === RPSStatus.PENDING;
  }

  get isInProgress(): boolean {
    return this.status === RPSStatus.IN_PROGRESS;
  }

  get isCompleted(): boolean {
    return this.status === RPSStatus.COMPLETED;
  }

  get isExpired(): boolean {
    return this.status === RPSStatus.EXPIRED;
  }

  get hasResponder(): boolean {
    return this.responderId !== null && this.responderId !== undefined;
  }

  get hasWinner(): boolean {
    return this.winnerId !== null && this.winnerId !== undefined;
  }

  get isDraw(): boolean {
    return this.isCompleted && this.winnerId === null;
  }
}
